class ListNode {
    int val;
    ListNode next = null;
 }
public class test4 {
    public boolean isPalindrome (ListNode head) {
        // write code here
        ListNode slow=head;
        ListNode fast=head;
        while (fast!=null&&fast.next!=null){
            slow=slow.next;
            fast=fast.next;
        }
        ListNode cur=slow.next;
        slow.next=null;
        while (cur!=null){
            ListNode curN=cur.next;//记录
            cur.next=slow;
            slow=cur;
            cur=curN;
        }
        ListNode cut=slow;
        while (cut!=null&&head!=null){
            if(head.val!=cut.val) {
                return false;
            }
            if(head==slow){
                return true;
            }
            cut=cut.next;
            head=head.next;
        }
        return true;
    }
}
